package com.um.jdy.mp.user.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.mp.user.entity.dto.EditPasswordDTO;
import com.um.jdy.mp.user.entity.dto.LoginDTO;
import com.um.jdy.mp.user.entity.dto.UserBindWXDTO;
import com.um.jdy.mp.user.entity.vo.MerchantVO;
import com.um.jdy.mp.user.entity.vo.PackageVO;
import com.um.jdy.mp.user.entity.vo.SigninVO;
import com.um.jdy.mp.user.manager.UserManager;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 我的-用户
 *
 * @author cs
 * 日期 2023/5/23
 * 版权所有 广州优匠科技有限公司
 */
@RestController
@RequestMapping("/api/v1/user")
@Api(tags = "用户")
@Validated
public class UserController extends BaseController<UserManager> {

    @ApiOperation(value = "密码登录")
    @PostMapping("/signin")
    public Response<SigninVO> signin(@RequestBody LoginDTO loginDTO) {
        return manager.signin(loginDTO.getMobile(), loginDTO.getPassword());
    }

    /**
     * 退出登录
     *
     * @return
     */
    @ApiOperation(value = "退出登录")
    @GetMapping("/signout")
    @SaCheckLogin
    public Response signout() {
        return manager.signout();
    }

    @ApiOperation(value = "查询个人资料")
    @GetMapping("/get")
    @SaCheckLogin
    public Response<MerchantVO> get() {
        return manager.get();
    }

    /**
     * 已登录用户：绑定微信
     * @param bindwxDTO
     * @return
     */
    @ApiOperation(value = "已登录用户：绑定微信")
    @PostMapping("/bindwx")
    public Response<SigninVO> bindwx(@RequestBody UserBindWXDTO bindwxDTO) {
        return manager.bindwx(bindwxDTO);
    }

    /**
     * 修改密码
     *
     * @param dto
     * @return
     */
//    @PutMapping("/edit_password")
//    @ApiOperation(value = "修改密码")
//    @SaCheckLogin
//    public Response editPassword(@RequestBody EditOldPasswordDTO dto) {
//        return manager.editPassword(dto.getOldPassword(), dto.getNewPassword());
//    }

    /**
     * 修改密码
     *
     * @param dto
     * @return
     */
    @PutMapping("/edit_password")
    @ApiOperation(value = "修改密码")
    @SaCheckLogin
    public Response editPassword(@RequestBody EditPasswordDTO dto) {
        return manager.editPassword(dto);
    }

    /**
     * 强制修改密码
     *
     * @param dto
     * @return
     */
    @PutMapping("/{id}/edit_password")
    @ApiOperation(value = "强制修改密码")
    @SaCheckLogin
    public Response editPassword(@PathVariable @NotNull String id, @RequestBody EditPasswordDTO dto) {
        return manager.editPasswordByParentId(id, dto.getNewPassword());
    }

    @ApiOperation(value = "查询平台使用套餐")
    @GetMapping("/app/package")
    @SaCheckLogin
    public Response<PackageVO> getAppPackage() {
        return manager.getAppPackage();
    }
}
